import { Rule, RuleType } from '@midwayjs/decorator'

export class LoginDTO {
  @Rule(RuleType.string().required())
  username: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string

  @Rule(RuleType.string())
  verify: string

  @Rule(RuleType.bool())
  remember_me: boolean
}

export class SystemUserDTO {
  @Rule(RuleType.string().required())
  username: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string

  @Rule(RuleType
    .string()
    .pattern(/^[0-9]+$/)
  )
  phone: string

  @Rule(RuleType.string().email())
  email: string

  @Rule(RuleType.bool())
  active: boolean

  @Rule(RuleType.number())
  role_id: number

  @Rule(RuleType.number())
  department_id: number

  @Rule(RuleType.array())
  district_id: number[]

  @Rule(RuleType.string())
  nickname: string
}

@Rule(SystemUserDTO)
export class SystemUserUpdateDTO extends SystemUserDTO {
  @Rule(RuleType.string().required())
  id: string

  @Rule(RuleType.string())
  username: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
  )
  password: string
}

export class SystemUserChangePasswordDTO {
  @Rule(RuleType.string().required())
  id: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  old_password: string

  @Rule(RuleType
    .string()
    .max(20)
    .min(6)
    .required()
  )
  password: string
}
